package game;

import game.GameDice.DiceType;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

public class GameReferee {
	
	public BoardState bs;
	
	public GameReferee(BoardState bs) {
		this.bs = bs;
	}
	
	public List<Point> getValidMoves(GameDice gd, BoardState bs) {
		Point p = new Point(gd.getPosition().x, gd.getPosition().y);
		List<Point> temp   = getShades(p, gd.getDiceType()); 
		List<Point> result = new ArrayList<Point>();
		while (temp.iterator().hasNext()) {
			Point itrp = temp.iterator().next();
			if (itrp.x>=0 && itrp.x<=8 && itrp.y>=0 && itrp.y<=7) {
				result.add(itrp);
			}
		}
		return result;
	}
	
	private List<Point> getShades(Point p, DiceType dt) {
		List<Point> result = new ArrayList<Point>();
		int bound = dt.toInt();
		for (int i=-bound; i<=bound; i++) {
			if (i==-bound || i==bound){
				result.add(new Point(p.x+i, p.y));
			}
			else if (i<=0 && i>-bound){
				result.add(new Point(p.x+i, p.y+i+bound));
				result.add(new Point(p.x+i, p.y-i-bound));
			}
			else {
				result.add(new Point(p.x+i, p.y-i+bound));
				result.add(new Point(p.x+i, p.y+i-bound));
			}
		}
		return result;
	}
	
}
